<?php

class cargo_wt extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'cargo_co':
	 * @var integer $id
	 * @var integer $do_id
	 * @var integer $company_id
	 * @var integer $type
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
         public $type = array('0'=>'KG','1'=>'Ton','2'=>'LBS');
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cargo_wt';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('wt_type, id', 'numerical', 'integerOnly'=>true),
                        array('wt','numerical'),
		);
	}
        public function save() {
            $returnID = 0;
            if($this->exists("wt=:wt AND wt_type=:wt_type", array(":wt"=>$this->wt,":wt_type"=>$this->wt_type))) {
                $returnID = $this->find("wt=:wt AND wt_type=:wt_type", array(":wt"=>$this->wt,":wt_type"=>$this->wt_type))->id;
            }
            else {
            if(!parent::save(false))
                return false;
            $returnID=$this->id;
            }
            return $returnID;
        }
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    'company'=>array(self::BELONGS_TO,'company','company_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'do_id' => 'Do',
			'company_id' => 'C/O',
			'type' => 'Type',
		);
	}
}